home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
v cisle
/
sadanastroju
/
wot-20080519-fx.xpi
/
chrome
/
wot.jar
/
content
/
ui.js
< prev
next >
Wrap
Text File
|
2008-05-17
|
11KB
|
422 lines
/*
ui.js
Copyright ⌐ 2005, 2006, 2007, 2008 Against Intuition, Inc. <info@mywot.com>
*/
var wot_ui =
{
init: function()
{
},
show_accessible: function()
{
try {
var mainwnd = document.getElementById("main-window");
if (mainwnd) {
var mode = "normal";
if (wot_prefs.accessible) {
mode = "accessible";
}
if (mainwnd.getAttribute("wot-mode") != mode) {
mainwnd.setAttribute("wot-mode", mode);
wot_my_session.update(false); /* Update cookies */
}
}
} catch (e) {
dump("wot_ui.show_accessible: failed with " + e + "\n");
}
},
show_toolbar_button: function(id, before)
{
try {
var nbr = document.getElementById("nav-bar");
if (!nbr || nbr.currentSet.indexOf(id) != -1) {
return;
}
var box = document.getElementById("navigator-toolbox");
if (!box) {
return;
}
var bar = box.firstChild;
while (bar) {
if (bar.currentSet && bar.currentSet.indexOf(id) != -1) {
return;
}
bar = bar.nextSibling;
}
var target = document.getElementById(before);
/* The before element might not exist in the nav-bar */
var elem = nbr.firstChild;
while (elem) {
if (elem == target) {
break;
}
elem = elem.nextSibling;
}
nbr.insertItem(id, elem, null, false);
document.persist("nav-bar", "currentset");
} catch (e) {
dump("wot_ui.show_toolbar_button: failed with " + e + "\n");
}
},
/* Shows or hides user interface elements based on preferences */
show_elements: function()
{
try {
/* Toolbar */
if (wot_prefs.create_button) {
this.show_toolbar_button("wot-button", "urlbar-container");
}
/* Accessibility */
this.show_accessible();
/* Rating components */
document.getElementById("wot-rating-1").hidden =
!wot_prefs.show_application_1;
document.getElementById("wot-rating-2").hidden =
!wot_prefs.show_application_2;
document.getElementById("wot-rating-4").hidden =
!wot_prefs.show_application_4;
} catch (e) {
dump("wot_ui.show_elements: failed with " + e + "\n");
}
},
update: function(description)
{
try {
wot_commands.update();
this.update_title(description);
this.update_rating();
this.update_testimonies();
this.update_scorecard();
this.update_users();
this.update_message();
this.update_updates();
} catch (e) {
dump("wot_ui.update: failed with " + e + "\n");
}
},
update_title: function(description)
{
try {
var title = document.getElementById("wot-title-text");
if (title) {
if (wot_cache.isok(wot_core.hostname)) {
title.value = wot_core.hostname;
title.setAttribute("status", "target");
} else {
title.value = description;
title.setAttribute("status", "information");
}
}
} catch (e) {
dump("wot_ui.update_title: failed with " + e + "\n");
}
},
update_rating: function()
{
try {
var cached = wot_cache.isok(wot_core.hostname);
for (var i = 0; i < WOT_APPLICATIONS; ++i) {
var reputation = document.getElementById("wot-rating-" + i +
"-reputation");
var confidence = document.getElementById("wot-rating-" + i +
"-confidence");
var rep = -1, cnf = -1;
if (cached) {
rep = wot_cache.get(wot_core.hostname, "reputation_" + i);
cnf = wot_cache.get(wot_core.hostname, "confidence_" + i);
}
if (reputation) {
if (rep >= WOT_MIN_REPUTATION_5) {
reputation.setAttribute("reputation", 5);
} else if (rep >= WOT_MIN_REPUTATION_4) {
reputation.setAttribute("reputation", 4);
} else if (rep >= WOT_MIN_REPUTATION_3) {
reputation.setAttribute("reputation", 3);
} else if (rep >= WOT_MIN_REPUTATION_2) {
reputation.setAttribute("reputation", 2);
} else if (rep >= 0) {
reputation.setAttribute("reputation", 1);
} else if (cached) {
reputation.setAttribute("reputation", 0);
} else {
reputation.removeAttribute("reputation");
}
}
if (confidence) {
if (cnf >= WOT_MIN_CONFIDENCE_5) {
confidence.setAttribute("confidence", 5);
} else if (cnf >= WOT_MIN_CONFIDENCE_4) {
confidence.setAttribute("confidence", 4);
} else if (cnf >= WOT_MIN_CONFIDENCE_3) {
confidence.setAttribute("confidence", 3);
} else if (cnf >= WOT_MIN_CONFIDENCE_2) {
confidence.setAttribute("confidence", 2);
} else if (cnf >= WOT_MIN_CONFIDENCE_1) {
confidence.setAttribute("confidence", 1);
} else {
confidence.setAttribute("confidence", 0);
}
}
}
} catch (e) {
dump("wot_ui.update_rating: failed with " + e + "\n");
}
},
/* Updates the testimony element */
update_testimonies: function(hover, pos)
{
try {
var cached = wot_cache.isok(wot_core.hostname);
/* CSS rules */
var sld_rule = wot_css.getstyle(WOT_STYLESHEET,
".wot-rating-slider");
if (!sld_rule) {
dump("wot_ui.update_testimonies: no style rule?\n");
return;
}
/* Dimensions */
var sld_w = wot_css.getstyle_numeric(sld_rule, "width");
/* Sliders */
for (var i = 0; i < WOT_APPLICATIONS; ++i) {
/* Slider elements */
var stack = document.getElementById("wot-rating-" + i +
"-stack");
var indicator = document.getElementById("wot-rating-" + i +
"-indicator");
if (!stack || !indicator) {
continue;
}
var testimony = -1;
if (cached) {
testimony = wot_cache.get(wot_core.hostname,
"testimony_" + i);
}
if (testimony >= 0) {
indicator.left = testimony * sld_w / WOT_MAX_REPUTATION;
if (testimony == WOT_MAX_REPUTATION) {
--indicator.left;
}
stack.setAttribute("testimony", "true");
} else if (hover != null && i == hover) {
indicator.left = pos * sld_w / WOT_MAX_REPUTATION;
if (pos == WOT_MAX_REPUTATION) {
--indicator.left;
}
stack.setAttribute("testimony", "hover");
} else {
stack.setAttribute("testimony", "false");
}
var help = document.getElementById("wot-rating-" + i +
"-help-text");
var link = document.getElementById("wot-rating-" + i +
"-help-link");
if (help && link) {
if (testimony >= WOT_MIN_REPUTATION_5) {
help.value = wot_util.getstring("help_5");
} else if (testimony >= WOT_MIN_REPUTATION_4) {
help.value = wot_util.getstring("help_4");
} else if (testimony >= WOT_MIN_REPUTATION_3) {
help.value = wot_util.getstring("help_3");
} else if (testimony >= WOT_MIN_REPUTATION_2) {
help.value = wot_util.getstring("help_2");
} else if (testimony >= 0) {
help.value = wot_util.getstring("help_1");
} else {
help.value = "";
}
link.removeAttribute("help");
link.value = "";
if (cached && testimony >= 0) {
var r = wot_cache.get(wot_core.hostname,
"reputation_" + i);
if (r != null && r >= 0 &&
Math.abs(r - testimony) > WOT_MIN_COMMENT_DIFF) {
help.value = wot_util.getstring("help_comment");
link.value = wot_util.getstring("help_comment_link");
link.setAttribute("comment", "true");
}
}
help.hidden = (!help.value || !help.value.length);
}
}
} catch (e) {
dump("wot_ui.update_testimonies: failed with " + e + "\n");
}
},
update_scorecard: function()
{
},
update_message: function()
{
try {
var msg = document.getElementById("wot-message");
var txt = document.getElementById("wot-message-text");
if (!msg || !txt || !txt.firstChild) {
return;
}
if (wot_api_query.message.length == 0 ||
wot_api_query.message_type.length == 0) {
msg.hidden = true;
txt.firstChild.nodeValue = "";
return;
}
txt.firstChild.nodeValue = wot_api_query.message;
txt.setAttribute("url-type",
wot_api_query.message_url.substring(0,4));
msg.setAttribute("message-status", wot_api_query.message_type);
msg.hidden = false;
} catch (e) {
dump("wot_ui.update_message: failed with " + e + "\n");
}
},
update_users: function()
{
try {
if (!wot_api_query.users) {
return;
}
var i, j = 0;
for (i = 0; i < wot_api_query.users.length; ++i) {
var user = document.getElementById("wot-user-" + j);
var content = document.getElementById("wot-user-" + j + "-content");
var stack = document.getElementById("wot-user-" + j + "-stack");
var header = document.getElementById("wot-user-" + j + "-header");
var bar = document.getElementById("wot-user-" + j + "-bar-image");
var label = document.getElementById("wot-user-" + j + "-bar-text");
var text = document.getElementById("wot-user-" + j + "-text");
var notice = document.getElementById("wot-user-" + j + "-notice");
if (!user || !header || !bar || !label || !text || !notice) {
return;
}
if (wot_api_query.users[i].bar &&
wot_api_query.users[i].length != null &&
wot_api_query.users[i].label) {
header.value = wot_api_query.users[i].bar;
label.value = wot_api_query.users[i].label;
bar.setAttribute("length", wot_api_query.users[i].length);
bar.hidden = false;
} else {
header.value = "";
label.value = "";
bar.hidden = true;
}
if (wot_api_query.users[i].url) {
content.setAttribute("url", wot_api_query.users[i].url);
} else {
content.removeAttribute("url");
}
if (wot_api_query.users[i].notice) {
notice.value = wot_api_query.users[i].notice;
notice.hidden = false;
} else {
notice.hidden = true;
}
if (wot_api_query.users[i].text) {
text.value = wot_api_query.users[i].text;
user.hidden = false;
++j;
} else {
text.value = "";
user.hidden = true;
}
}
} catch (e) {
dump("wot_ui.update_users: failed with " + e + "\n");
}
},
update_updates: function()
{
try {
var updbox = document.getElementById("wot-update");
if (!updbox) {
return;
}
updbox.hidden = !wot_update.isavailable();
} catch (e) {
dump("wot_ui.update_updates: failed with " + e + "\n");
}
},
geticonurl: function(r, size, plain)
{
var image = "no_rep_available";
if (r >= WOT_MIN_REPUTATION_5) {
image = "trusted";
} else if (r >= WOT_MIN_REPUTATION_4) {
image = "alright";
} else if (r >= WOT_MIN_REPUTATION_3) {
image = "caution";
} else if (r >= WOT_MIN_REPUTATION_2) {
image = "not_safe";
} else if (r >= 0) {
image = "danger";
}
var base = "chrome://wot/skin/fusion/";
if (wot_prefs.accessible) {
base += "accessible/";
}
return base + size + "_" + size +
((plain) ? "/plain/" : "/") + image + ".png";
}
};
wot_ui.init();